package com.pro.grpcserver;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

public class PropertiesUtil {

    private static Properties _prop = new Properties();

    /**
     * 读取配置文件
     * @param fileName
     */
    public static void readProperties(String fileName){
        try {
            InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName);
            BufferedReader bf = new BufferedReader(new InputStreamReader(in));
            _prop.load(bf);
            String dev = _prop.getProperty("spring.profiles.active");
            InputStream in2 = PropertiesUtil.class.getClassLoader().getResourceAsStream("application" +"-"+dev+".properties");
            BufferedReader bf2 = new BufferedReader(new InputStreamReader(in2));
            _prop.load(bf2);
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    /**
     * 根据key读取对应的value
     * @param key
     * @return
     */
    public static String getProperty(String key){
        return _prop.getProperty(key);
    }
}
